/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ipo.mm.ejb.facade.document;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.ipo.mm.ejb.entities.Document;
import org.ipo.mm.ejb.entities.Meeting;

/**
 *
 * @author makcro
 */
@Stateless
public class DocumentFacade implements DocumentFacadeLocal, DocumentFacadeRemote {
    @PersistenceContext
    private EntityManager em;

    public void create(Document document) {
        em.persist(document);
    }

    public void edit(Document document) {
        em.merge(document);
    }

    public void remove(Document document) {
        em.remove(em.merge(document));
    }

    public Document find(Object id) {
        return em.find(Document.class, id);
    }

    public List<Document> findAll() {
        return em.createQuery("select object(o) from Document as o").getResultList();
    }

    public java.util.List<Document> findByMeeting(Meeting meeting) {
        Query q = em.createNamedQuery("Document.findByMeeting");
        q.setParameter("meeting", meeting);

        return q.getResultList();
    }

}
